﻿@using ETD.Common.Extension;
@using ETD.WebOrganization.Libs.Helper;
@using ETD.WinClient.Config;
@using ETD.Domain.EnumModels;
@using ETD.Domain.WebModels;
@using ETD.Common;
@model ETD.WebOrganization.Areas.Web.Models.SettlementEditModel
@{

}
<style>
    .text-left {
        text-align: left;
    }

    .weui-form-preview__hd:after {
        left: 0px;
    }

    .weui-form-preview__ft {
        margin-top: 30px;
    }

    .weui-btn_primary {
        background-color: #4dd1c1;
        width: 300px;
    }

    .weui-form-preview:after {
        border-bottom: 0px;
    }

    .font12 {
        font-size: 12px !important;
    }

    .weui-cell_access .weui-cell__ft {
        padding-right: 0px;
    }

        .weui-cell_access .weui-cell__ft:after {
            content: none;
        }
</style>
<div class="weui-cells weui-cells_form">
    <a class="weui-cell weui-cell_access" href="">
        <div class="weui-cell__bd">
            <p>到账银行卡</p>
        </div>
        <div class="weui-cell__ft font12">
            @Html.Hidden("hdnOrganizationBankID", Model.OrganizationBankID)
            <div>@Model.BankSummary</div>
            <div>1-3个工作日到账&nbsp;&nbsp;</div>
        </div>
    </a>

    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd">
            <label class="weui-label">结算金额</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="txtAmount" placeholder="请填写金额" type="number">
        </div>
        <div class="weui-cell__ft">
            <button class="weui-vcode-btn font12" id="btnSettlementAll">全部结算</button>
        </div>
    </div>

</div>
<div class="weui-form-preview">
    <div class="weui-form-preview__hd">
        <div class="weui-form-preview__item">
            @Html.Hidden("hdnNotSettlementIncome", Model.NotSettlementIncome)
            <label class="weui-form-preview__label" style="font-size:14px;">可结算金额 ¥@Model.NotSettlementIncome.ToF2OrMark()</label>
            <em class="weui-form-preview__value" style="font-size:14px;color:#999999;">结算相关问题，点击查看</em>
        </div>
    </div>

    <div class="weui-btn-area">
        <a class="weui-btn weui-btn_primary" href="javascript:" id="btnSettlement">结算</a>
    </div>

</div>
@section ScriptSection{
    <script>
        $(function () {
            PageObj.init();
        });
        var PageObj = {};
        PageObj.init = function () {
            InputHelper.numInput("txtAmount");
            $("#btnSettlement").click(PageObj.onBtnSettlementClick);
            $("#btnSettlementAll").click(PageObj.onBtnSettlementAllClick);
        };
        PageObj.onBtnSettlementClick = function () {

            if (!($("#hdnOrganizationBankID").val() > 0)) {
                $.toptip('没有绑定银行卡，请绑定', 'warning');
                return false;
            }
            if (!($("#txtAmount").val() > 0)) {
                $.toptip('请填写结算金额', 'warning');
                return false;
            }
            if (parseFloat($("#txtAmount").val()) > parseFloat($("#hdnNotSettlementIncome").val())) {
                $.toptip('结算金额超限', 'warning');
                return false;
            }

            PageObj.confirmSettlement();
        };
        PageObj.onBtnSettlementAllClick = function () {
            $("#txtAmount").val($("#hdnNotSettlementIncome").val());
        }

        PageObj.confirmSettlement = function () {
            $.confirm("确定要结算吗?", "确认?", function () {
                //$.toast("文件已经删除!");
                PageObj.settlement(function () {
                    setTimeout(function () {
                        WinHelper.redirect("@Url.Action("FinancialIndex", "Financial")");
                    }, 1000);
                });

            }, function () {
                //取消操作
            });
        }

        PageObj.settlement = function (callBack) {
            var paras = {};
            paras.Amount = $("#txtAmount").val();
            ajaxPost("@Url.Action("Settlement", "Financial")", paras, function (data) {
                console.log(data);
                if (data.Status) {
                    $.toast("操作完成!");
                    callBack();
                } else {
                    $.toast(data.Info, "forbidden");
                }
            });
        }

    </script>
}
